<div class="footer-box">
  <footer class="footer">
    <center>
      已运行:<span id="run_time"></span>
      <span class="post-meta-divider">|</span>
      已咕咕:<span id="gugu_time"></span>
    </center>

    总字数:<span id="word_count"></span>
    <span class="post-meta-divider">|</span>
    <span id="busuanzi_container_site_pv">浏览数:<span id="busuanzi_value_site_pv"></span> 次</span>
    <span class="post-meta-divider">|</span>
    <span id="busuanzi_container_site_uv">访客数:<span id="busuanzi_value_site_uv"></span> 人</span>

    <script>
      function runTime() {
        str = "";
        BirthDay = new Date("January 30,2019");
        today = new Date();
        timeold = today.getTime() - BirthDay.getTime();
        msPerDay = 24 * 60 * 60 * 1000;
        e_daysold = timeold / msPerDay;
        daysold = Math.floor(e_daysold);
        str += daysold + "天";
        return str;
      }
      setInterval(function () {
        $("#run_time").html(runTime());
      }, 1000);
    </script>

    <script>
      function guguTime() {
        str = "";
        guguDay = new Date(document.lastModified);
        today = new Date();
        timeold = today.getTime() - guguDay.getTime();
        msPerDay = 24 * 60 * 60 * 1000;
        e_daysold = timeold / msPerDay;
        daysold = Math.floor(e_daysold);
        str += daysold + "天";
        return str;
      }
      setInterval(function () {
        $("#gugu_time").html(guguTime());
      }, 1000);
    </script>

    <script>
      function site() {

        return 275.6 + "k";
      };

      setInterval(function () {
        $("#word_count").html(site());
      }, 1000);
    </script>

    <div class="copyright">
      Created by
      <a href="https://github.com/YuZhangWang" target="_blank">YuZhangWang</a>
      ©2019-Present
      <span class="post-meta-divider">|</span>
      Powered By
      <a href="https://github.com/YuZhangWang/YuZhangWang.github.io" target="_blank">Github</a>
      <span class="post-meta-divider">|</span>
      Theme By
      <a href="https://github.com/theme-next/hexo-theme-next" target="_blank">Next</a>
    </div>
    <div class="poweredby">
      <%- site.themeConfig.footerInfo%>
    </div>
  </footer>
  <% let scheme=site.customConfig.scheme || 'pisces' ; %>
    <% if (scheme==='muse' || scheme==='mist' ) { %>
      <div class="drawer-box <%= site.customConfig.sideIsRight?'right':'left' %>" id="drawer_box">
        <span class="muse-line muse-line-first"></span>
        <span class="muse-line muse-line-middle"></span>
        <span class="muse-line muse-line-last"></span>
      </div>
      <% } %>
        <div class="<%= scheme !==''?scheme:'pisces' %> back-to-top" id="back_to_top">
          <i class="fa fa-arrow-up"></i>
          <% if (!(scheme==='muse' || scheme==='mist' )) { %>
            <span class="scrollpercent"> <span id="back_to_top_text">0</span>% </span>
            <% } %>
        </div>
        <% if (site.customConfig.bgImg !=='' || site.customConfig.bgImgUrl !=='' ) { %>
          <% let bgurl=site.customConfig.bgImgUrl || site.customConfig.bgImg; bgurl=bgurl && bgurl.startsWith('http') ?
            bgurl: site.customConfig.cdn + bgurl;%>
            <% if (bgurl && bgurl !=='' ) { %>
              <div class="bg-img">
                <img src="<%= bgurl %>" />
              </div>
              <% } %>
                <% } %>
                  <% if (site.customConfig.enableLive2d) { %>
                    <%- include('./live2d.ejs') %>
                      <% } %>
                        <% if (site.customConfig.bgMusic !=='none' ) { %>
                          <%- include('./music.ejs') %>
                            <% } %>
</div>
<script>
  let sideBarOpen = "sidebar-open";
  let body = document.body;
  let back2Top = document.querySelector("#back_to_top"),
    back2TopText = document.querySelector("#back_to_top_text"),
    drawerBox = document.querySelector("#drawer_box"),
    rightSideBar = document.querySelector(".sidebar"),
    viewport = document.querySelector("body");

  function scrollAnimation(currentY, targetY) {
    let needScrollTop = targetY - currentY;
    let _currentY = currentY;
    setTimeout(() => {
      const dist = Math.ceil(needScrollTop / 10);
      _currentY += dist;
      window.scrollTo(_currentY, currentY);
      if (needScrollTop > 10 || needScrollTop < -10) {
        scrollAnimation(_currentY, targetY);
      } else {
        window.scrollTo(_currentY, targetY);
      }
    }, 1);
  }

  back2Top.addEventListener("click", function (e) {
    scrollAnimation(document.scrollingElement.scrollTop, 0);
    e.stopPropagation();
    return false;
  });

  window.addEventListener("scroll", function (e) {
    let percent =
      (document.scrollingElement.scrollTop /
        (document.scrollingElement.scrollHeight -
          document.scrollingElement.clientHeight)) *
      100;
    if (percent > 1 && !back2Top.classList.contains("back-top-active")) {
      back2Top.classList.add("back-top-active");
    }
    if (percent == 0) {
      back2Top.classList.remove("back-top-active");
    }
    if (back2TopText) {
      back2TopText.textContent = Math.floor(percent);
    }
  });

  let hasCacu = false;
  window.addEventListener("resize", function (e) {
    calcuHeight();
  });

  function calcuHeight() {
    // 动态调整站点概览高度
    if (
      (!hasCacu && back2Top.classList.contains("pisces")) ||
      back2Top.classList.contains("gemini")
    ) {
      let sideBar = document.querySelector(".sidebar");
      let navUl = document.querySelector("#site_nav");
      sideBar.style =
        "margin-top:" + (navUl.offsetHeight + navUl.offsetTop + 15) + "px;";
      hasCacu = true;
    }
  }
  calcuHeight();

  let open = false,
    MOTION_TIME = 300,
    RIGHT_MOVE_DIS = "320px";

  if (drawerBox) {
    let rightMotions = document.querySelectorAll(".right-motion");
    let right = drawerBox.classList.contains("right");

    let transitionDir = right
      ? "transition.slideRightIn"
      : "transition.slideLeftIn";

    let openProp, closeProp;
    if (right) {
      openProp = {
        paddingRight: RIGHT_MOVE_DIS,
      };
      closeProp = {
        paddingRight: "0px",
      };
    } else {
      openProp = {
        paddingLeft: RIGHT_MOVE_DIS,
      };
      closeProp = {
        paddingLeft: "0px",
      };
    }

    drawerBox.onclick = function () {
      open = !open;
      jQuery.Velocity(rightSideBar, "stop");
      jQuery.Velocity(viewport, "stop");
      jQuery.Velocity(rightMotions, "stop");
      if (open) {
        jQuery.Velocity(
          rightSideBar,
          {
            width: RIGHT_MOVE_DIS,
          },
          {
            duration: MOTION_TIME,
            begin: function () {
              jQuery.Velocity(rightMotions, transitionDir, {});
            },
          }
        );
        jQuery.Velocity(viewport, openProp, {
          duration: MOTION_TIME,
        });
      } else {
        jQuery.Velocity(
          rightSideBar,
          {
            width: "0px",
          },
          {
            duration: MOTION_TIME,
            begin: function () {
              jQuery.Velocity(rightMotions, {
                opacity: 0,
              });
            },
          }
        );
        jQuery.Velocity(viewport, closeProp, {
          duration: MOTION_TIME,
        });
      }
      for (let i = 0; i < drawerBox.children.length; i++) {
        drawerBox.children[i].classList.toggle("muse-line");
      }
      drawerBox.classList.toggle(sideBarOpen);
    };
  }

  // 链接跳转
  let newWindow = "<%= site.customConfig.newWindow %>";
  if (newWindow === "true") {
    let links = document.querySelectorAll(".post-body a");
    links.forEach((item) => {
      if (!item.classList.contains("btn")) {
        item.setAttribute("target", "_blank");
      }
    });
  }

  let faSearch = document.querySelector("#fa_search");
  faSearch &&
    faSearch.addEventListener("click", function () {
      document.querySelector("#search_mask").style = "";
    });

  // 代码高亮
  hljs.initHighlightingOnLoad();

  // 离开当前页title变化
  var leaveTitle = "<%- site.customConfig.leaveTitle %>";
  var normal_title = document.title;
  if (leaveTitle) {
    document.addEventListener("visibilitychange", function () {
      if (document.visibilityState == "hidden") {
        normal_title = document.title;
        document.title = leaveTitle;
      } else {
        document.title = normal_title;
      }
    });
  }
</script>

<link rel="stylesheet" href="<%= site.customConfig.cdn %>/media/css/jquery.fancybox.css" />
<script src="<%= site.customConfig.cdn %>/media/js/jquery.fancybox.js"></script>

<script>
  let images = document.querySelectorAll(".section img");
  images.forEach((image) => {
    var parent = image.parentElement;
    var next = image.nextElementSibling;
    parent.removeChild(image);
    var aelem = document.createElement("a");
    aelem.href = image.src;
    aelem.dataset["fancybox"] = "images";
    aelem.dataset["rel"] = "fancybox-button";
    aelem.classList.add("fancybox");
    aelem.appendChild(image);
    parent.insertBefore(aelem, next);
  });
</script>